import java.util.ArrayList;
import java.util.List;

public class Solution6 {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(3);
        root.left.right = new TreeNode(5);
        System.out.println(binaryTreePaths(root));
    }
    public static List<String> ret = new ArrayList<>();;
    public static List<String> binaryTreePaths(TreeNode root) {
        dfs(root, new StringBuffer());
        return ret;
    }

    public static void dfs(TreeNode root, StringBuffer _path) {
        StringBuffer path = new StringBuffer(_path);
        path.append(Integer.toString(root.val));
        if(root.left == null && root.right == null) {
            ret.add(path.toString());
            return;
        }
        path.append("->");
        if(root.left != null) {
            dfs(root.left,path);
        }
        if(root.right != null) {
            dfs(root.right,path);
        }
    }
}